from selenium import webdriver
from selenium.webdriver.common.by import By
from time import sleep
class BasePage:
    def __init__(self,driver):
        self.driver=driver
    def get_url(self,url):
        '''实现打开url界面'''
        self.driver.get(url)
        self.driver.maximize_window()
    def find_ele(self,loc):
        '''实现元素定位'''
        ele=self.driver.find_element(*loc)
        return ele
    def input_ele(self,loc,value):
        '''实现输入框输入数据'''
        ele=self.find_ele(loc)
        ele.send_keys(value)
    def ele_click(self,loc):
        ele=self.find_ele(loc)
        ele.click()
    def ele_clear(self,loc):
        ele=self.find_ele(loc)
        ele.clear()
if __name__ == '__main__':
    chrome_local=r'D:\Soft\chrome-win\chrome.exe'
    options=webdriver.ChromeOptions()
    options.binary_location=chrome_local
    driver=webdriver.Chrome(options=options)
    url=r'https://www.baidu.com/'
    kw_loc = (By.ID, 'kw')
    su_loc = (By.ID, 'su')
    value='selenium'
    basepage=BasePage(driver)
    basepage.get_url(url)
    basepage.ele_clear(kw_loc)
    basepage.input_ele(kw_loc,value)
    basepage.ele_click(su_loc)
    sleep(3)
    driver.quit()
